<template>
<div>
  <div class="body">
  <div class="header">
    <div class="header-content">
      <div class="into-class">
        <div>
          <a class="jump-home" @click="jumpToHome">
            <img src="../assets/img/other/keTangLogo.png" alt="ha" style="width: 112px;height: 28px;">
          </a>
        </div>
        <div class="header-title">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path:'/main' }" style="font-size: 18px; font-weight: normal;">我的课堂</el-breadcrumb-item>
          <el-breadcrumb-item :to="{ path:'/classDetail' }" style="font-size: 18px">课堂内容</el-breadcrumb-item>
          <el-breadcrumb-item style="font-size: 18px">成员管理</el-breadcrumb-item>
        </el-breadcrumb>
        </div>
      </div>
      <div class="user-center">
        <span title="任务管理" class="task">
          <i class="el-icon-s-claim new"></i>
        </span>
        <el-popover
            popper-class="area_popper"
            placement="bottom-start"
            trigger="click"
        >
          <div class="notice">
            <el-tabs v-model="activeName" @tab-click="handleClick">
              <el-tab-pane label="全部" name="first"></el-tab-pane>
              <el-tab-pane label="教学活动" name="second"></el-tab-pane>
              <el-tab-pane label="教务通知" name="third"></el-tab-pane>
              <el-tab-pane label="系统通知" name="fourth"></el-tab-pane>
            </el-tabs>
            <div class="notice-foot">
              <div class="btn">
                <i class="el-icon-check"></i>
                <el-button type="text">一键标为已读</el-button>
              </div>
              <div class="btn">
                <i class="el-icon-view"></i>
                <el-button type="text">查看全部</el-button>
              </div>
            </div>
          </div>
          <div slot="reference"><i class="el-icon-bell new"></i></div>
        </el-popover>
        <el-dropdown @command="handleCommand" trigger="click">
          <div ><img src="../assets/img/other/user.png" alt="ha" class="userImg"></div>
          <el-dropdown-menu>
            <el-dropdown-item command="a"><i class="el-icon-bank-card"></i>开通VIP</el-dropdown-item>
            <el-dropdown-item command="b"><i class="el-icon-link"></i>机构用户认证</el-dropdown-item>
            <el-dropdown-item command="c"><i class="el-icon-setting"></i> 个人设置</el-dropdown-item>
            <el-dropdown-item command="d"><i class="el-icon-right"></i> 退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </div>

    <div class="main-content">
      <div class="member-choose">
        <div class="choose-title">
          <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
            <el-menu-item index="1" style="font-size: 20px;margin-left: 30px" @click="setContentID('allMember')">全部成员</el-menu-item>
            <el-menu-item index="2" style="font-size: 20px;margin-left: 90px" @click="setContentID('studentGroup')">学生分组</el-menu-item>
          </el-menu>
        </div>
        <el-row class="tac" style="margin-left: 30px" v-if="ContentID === 'allMember'">
          <el-col :span="12">
<!--            这里的默认选中有问题，没有实现-->
            <el-menu
                default-active="teacher"
                class="el-menu-vertical-demo"
                @select="SelectMember"
               >
              <el-menu-item index="teacher" style="width: 250px;" @click="setID('teacher')">
                <span slot="title" style="font-size: 18px;color: black;font-weight: 700">教学团队</span>
              </el-menu-item>
              <el-submenu index="2" style="width: 250px;">
                <template slot="title">
                  <span style="font-size: 18px;color: black;font-weight: 700" selected>学生信息</span>
                </template>
                <el-menu-item-group>
                  <el-menu-item index="2-1" style="font-size: 15px;color: black;font-weight: 500" @click="setID('student')">全部学生</el-menu-item>
                  <el-menu-item index="2-2" style="font-size: 15px;color: black;font-weight: 500" @click="setID('student')">默认标签</el-menu-item>
                </el-menu-item-group>
              </el-submenu>


            </el-menu>
          </el-col>
        </el-row>

        <el-row v-if="ContentID === 'studentGroup'" style="margin-left: 30px">
          <el-menu
              default-active="teacher"
              class="el-menu-vertical-demo"
          >
            <el-submenu index="2" style="width: 250px;">
              <template slot="title">
                <span style="font-size: 18px;color: black;font-weight: 700" selected>课程固定分组</span>
              </template>
              <el-menu-item-group>

              </el-menu-item-group>
            </el-submenu>


          </el-menu>
        </el-row>

      </div>

      <div class="member-list">
        <el-row v-if="ContentID === 'allMember'">
        <div class="list-title">
          <p class="title-text">{{this.selectedText}}</p>
          <el-row class="total-member" v-if="id === 'teacher'">共{{this.teacherNums}}人</el-row>
          <el-row class="total-member" v-if="id === 'student'">共{{this.studentsNums}}人</el-row>
        </div>
        <div class="list-content">
<!--          教师列表-->
          <el-table
              :data="tableData"
              style="width: 100%"
              v-if="id === 'teacher'"
          >
            <el-table-column
                prop="name"
                label="教师姓名"
                width="180">
            </el-table-column>
            <el-table-column
                prop="account"
                label="账号"
                width="180">
            </el-table-column>
            <el-table-column
                prop="school"
                label="学校"
                width="180">
            </el-table-column>
            <el-table-column
                align="right">
              <template slot="header" slot-scope="scope">
                <el-input
                    v-model="search"
                    size="mini"
                    placeholder="输入关键字搜索"
                    @input="handleSearch(scope.input)"/>
              </template>
            </el-table-column>
          </el-table>

<!--          学生列表-->
          <el-table
              :data="studentData"
              style="width: 100%"
              v-if="id === 'student'"
          >
            <el-table-column
                prop="name"
                label="全部学员"
                width="180">
            </el-table-column>
            <el-table-column
                prop="studentId"
                label="学号"
                width="180">
            </el-table-column>
            <el-table-column
                prop="account"
                label="账号"
                width="180">
            </el-table-column>
            <el-table-column
                prop="school"
                label="学校"
                width="180">
            </el-table-column>
            <el-table-column
                align="right">
              <template slot="header" slot-scope="scope">
                <el-input
                    v-model="search"
                    size="mini"
                    placeholder="输入关键字搜索"
                    @input="handleSearch(scope.input)"/>
              </template>
            </el-table-column>
          </el-table>

<!--          教师列表分页器-->
          <div class="pagination">
          <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage4"
              :page-sizes="[15]"
              :page-size="15"
              layout="total, sizes, prev, pager, next"
              :total="this.teacherNums"
              v-if="id === 'teacher'"
          >
          </el-pagination>
          </div>
<!--          学生列表分页器-->
          <div class="pagination">
          <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage4"
              :page-sizes="[20]"
              :page-size="20"
              layout="total, sizes, prev, pager, next"
              :total="this.studentsNums"
              v-if="id === 'student'"
          >
          </el-pagination>

          </div>

        </div>
        </el-row>

<!--        分组页面-->

        <el-row v-if="ContentID === 'studentGroup'">
        <div class="list-title-group">
          <p>全部成员</p>
          <p>学号</p>
          <p>账号</p>
          <p>身份</p>
          <p>加入时间</p>
        </div>
          <el-empty description="暂无分组信息"></el-empty>
        </el-row>
        <div class="pagination">
          <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage4"
              :page-sizes="[20]"
              :page-size="20"
              layout="total, sizes, prev, pager, next"
              :total="0"
              v-if="ContentID === 'studentGroup'"
          >
          </el-pagination>

        </div>
      </div>
    </div>





  </div>
</div>
</template>

<script>
export default {
  name: "MemberManagePage",
  data() {
    return {
      activeName: 'first',
      activeIndex: '1',
      // 存储选中的文本信息
      selectedText: '教学团队',
      tableData: [],
      studentData: [],
      id: 'teacher',
      search: '',
      //接受传递过来的路由参数
      courseCode: this.$route.query.courseCode,
      currentPage4: 1,
      teacherNums:0,
      studentsNums:0,
      ContentID:'allMember',
    }
  },
  mounted() {
    this.findTeacher()
    this.findStudent()
    console.log(this.courseCode)
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    setID(id) {
      this.id = id;
      // console.log("当前的id为：" + this.id)
    },
    setContentID(contentID){
      this.ContentID = contentID;
    },

    jumpToHome() {
      this.$router.push('/bigPage/homepage')
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    handleCommand(command) {
      console.log(command)
      if (command === "d") {
        localStorage.removeItem("token")
        localStorage.removeItem("role")
        this.jumpToHome()
      }
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    SelectMember(key, indexPath) {
      const textMap = {
        'teacher': '教学团队',
        '2-1': '全部学生',
        '2-2': '默认标签'
      };
      // 设置选中的文本信息
      this.selectedText = textMap[key] || '未找到文本';
      // console.log('选中的文本信息:', this.selectedText);
    },

    handleSearch() {
      console.log(this.search)
    },

    //通过课程号查询到课程id，再通过课程id查询到教师id，再通过教师id查询到教师姓名和学校
    findTeacher() {
      this.request.get("/getCourseIdByCode?courseCode=" + this.courseCode).then(res => {
        // console.log(res)
        this.tableData = res.teachers
        this.teacherNums = res.teacherNums
      }).catch(err => {
        console.log(err)
      })
    },

    //通过课程号查询到课程id，再通过课程id查询到学生id，再通过学生id查询到学生学号、姓名和学校
    findStudent() {
      this.request.get("/getCourseIdByCodeForStudent?courseCode=" + this.courseCode).then(res => {
        // console.log(res)
        this.studentData = res.students
        this.studentsNums = res.studentsNums
      }).catch(err => {
        console.log(err)
      })
    },


  },


}
</script>

<style scoped>
*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.header {
  height: 80px;
  width: 100%;
  margin-bottom: 16px;
  box-sizing: border-box;
  box-shadow: 0 0 10px #ccc;
}
.header-content {
  position: fixed;
  background-color: #fff;
  z-index: 999;
  top: 0;
  left: 0;
  height: 80px;
  width: 100%;
  padding: 0 40px;
  min-width: 900px;
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 0 0 #dfdfdf;
}
.into-class {
  display: flex;
  justify-content: space-between;
}
.jump-home {
  cursor: pointer;
}
.user-center {
  display: flex;
  align-items: center;
}
.notice-foot {
  margin-top: 30px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  color: #4285f4;
  line-height: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btn {
  font-size: 18px;
  cursor: pointer;
  width: 50%;
  height: 50px;
  line-height: 50px;
}
.new {
  font-size: 30px;
  margin-right: 18px;
}
.userImg{
  width: 40px;
  height: 40px;
}
.header-title{
  font-weight: 700;
  margin-top: 5px;
  margin-left: 60px;

}
.body{
  width: 100%;
  height: 100%;
}
.main-content{
  width: 100%;
  height: 100vh;
  display: flex;
  /*background-color: #4285f4;*/
}
.member-choose {
  background-color: #fff;
  display: block;
  padding: 1rem;
  width: 350px;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  height: 600px;
  border: 1px solid #ccc;
  margin-left: 20vh;
  margin-top: 5vh;
}
.member-list{
  background-color: #fff;
  display: block;
  padding: 1rem;
  width: 950px;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  height: 750px;
  border: 1px solid #ccc;
  margin-left: 5vh;
  margin-top: 5vh;
}
.el-menu-demo{
  border-bottom: none;
}
.el-menu-vertical-demo{
  border-right: none;
}
.list-title{
  display: flex;
  margin-left: 20px;
}
.list-title-group{
  display: flex;
  margin-left: -16px;
  height: 60px;
  width: 947px;
  background-color: #f6f6f6;
  margin-top: -16px;
  border-radius: 0.5rem;
}
.list-title-group p{
  margin-left: 110px;
  font-size: 20px;
  font-weight: 700;
  margin-top: 13px;
}
.total-member{
  color: #909399;
  font-size: 14px;
  margin-left: 20px;
  margin-top: 10px;
}
.title-text{
  font-weight: 700;
  font-size: 24px;
}
.pagination{
  position: absolute;
  width: 950px;
  text-align: center;
  margin-top: 50px;
}
.el-empty{
  height: 600px;
}

</style>